package com.ruoyi.app.zzq.controller;

import com.ruoyi.app.zzq.domain.Partydues;
import com.ruoyi.app.zzq.service.ViewService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

@RestController
@RequestMapping("/view")
public class ViewController  extends BaseController {
    @Autowired
    private ViewService viewService;

    @ApiOperation("查看我的党费")
    @GetMapping(value = "/mypartyDues")
    public AjaxResult SelectUserById(String startDate, String endDate) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.setTime(sdf.parse(endDate));
        c.add(Calendar.DATE, 1);  // number of days to add
        endDate = sdf.format(c.getTime());  // dt is now the new date
        Long userId = SecurityUtils.getLoginUser().getUserId();
        List<Partydues> list=viewService.SelectpartyDues(userId+"",startDate,endDate);
        System.out.println(list);
        return AjaxResult.success(list);
    }

    @ApiOperation("查看我的活动")
    @GetMapping(value = "/myactives")
    public AjaxResult SelectmyActiveByid(String idNum)
    {
        return AjaxResult.success(viewService.SelectmyActiveByid(idNum));
    }
    @ApiOperation("查看活动详情")
    @GetMapping(value = "/activeInfo")
    public AjaxResult SelectActiveByid(String activeId)
    {
        return AjaxResult.success(viewService.SelectActiveByid(activeId));
    }
}
